////////////////////////////////////////////////////////////////////////////////
// The following FIT Protocol software provided may be used with FIT protocol
// devices only and remains the copyrighted property of Dynastream Innovations Inc.
// The software is being provided on an "as-is" basis and as an accommodation,
// and therefore all warranties, representations, or guarantees of any kind
// (whether express, implied or statutory) including, without limitation,
// warranties of merchantability, non-infringement, or fitness for a particular
// purpose, are specifically disclaimed.
//
// Copyright 2008 Dynastream Innovations Inc.
////////////////////////////////////////////////////////////////////////////////
// ****WARNING****  This file is auto-generated!  Do NOT edit this file.
// Profile Version = 1.50Release
// Tag = $Name: AKW1_500 $
////////////////////////////////////////////////////////////////////////////////


#include <istream>
#include "fit_mesg_broadcaster.hpp"

namespace fit
{

MesgBroadcaster::MesgBroadcaster(void)
{
}

FIT_BOOL MesgBroadcaster::Run(std::istream& file)
{
   Decode decode;
   return decode.Read(file, *this, *this);
}

void MesgBroadcaster::AddListener(MesgDefinitionListener& mesgDefinitionListener)
{
   mesgDefinitionListeners.push_back(&mesgDefinitionListener);
}

void MesgBroadcaster::AddListener(MesgListener& mesgListener)
{
   mesgListeners.push_back(&mesgListener);
}

void MesgBroadcaster::AddListener(MesgWithEventListener& mesgListener)
{
   mesgWithEventBroadcaster.AddListener(mesgListener);
}

void MesgBroadcaster::AddListener(BufferedRecordMesgListener& bufferedRecordMesgListener)
{
   bufferedRecordMesgBroadcaster.AddListener(bufferedRecordMesgListener);
}

void MesgBroadcaster::AddListener(FileIdMesgListener& fileIdMesgListener)
{
   fileIdMesgListeners.push_back(&fileIdMesgListener);
}
void MesgBroadcaster::AddListener(FileCreatorMesgListener& fileCreatorMesgListener)
{
   fileCreatorMesgListeners.push_back(&fileCreatorMesgListener);
}
void MesgBroadcaster::AddListener(PadMesgListener& padMesgListener)
{
   padMesgListeners.push_back(&padMesgListener);
}
void MesgBroadcaster::AddListener(SoftwareMesgListener& softwareMesgListener)
{
   softwareMesgListeners.push_back(&softwareMesgListener);
}
void MesgBroadcaster::AddListener(CapabilitiesMesgListener& capabilitiesMesgListener)
{
   capabilitiesMesgListeners.push_back(&capabilitiesMesgListener);
}
void MesgBroadcaster::AddListener(FileCapabilitiesMesgListener& fileCapabilitiesMesgListener)
{
   fileCapabilitiesMesgListeners.push_back(&fileCapabilitiesMesgListener);
}
void MesgBroadcaster::AddListener(MesgCapabilitiesMesgListener& mesgCapabilitiesMesgListener)
{
   mesgCapabilitiesMesgListeners.push_back(&mesgCapabilitiesMesgListener);
}
void MesgBroadcaster::AddListener(FieldCapabilitiesMesgListener& fieldCapabilitiesMesgListener)
{
   fieldCapabilitiesMesgListeners.push_back(&fieldCapabilitiesMesgListener);
}
void MesgBroadcaster::AddListener(DeviceSettingsMesgListener& deviceSettingsMesgListener)
{
   deviceSettingsMesgListeners.push_back(&deviceSettingsMesgListener);
}
void MesgBroadcaster::AddListener(UserProfileMesgListener& userProfileMesgListener)
{
   userProfileMesgListeners.push_back(&userProfileMesgListener);
}
void MesgBroadcaster::AddListener(HrmProfileMesgListener& hrmProfileMesgListener)
{
   hrmProfileMesgListeners.push_back(&hrmProfileMesgListener);
}
void MesgBroadcaster::AddListener(SdmProfileMesgListener& sdmProfileMesgListener)
{
   sdmProfileMesgListeners.push_back(&sdmProfileMesgListener);
}
void MesgBroadcaster::AddListener(BikeProfileMesgListener& bikeProfileMesgListener)
{
   bikeProfileMesgListeners.push_back(&bikeProfileMesgListener);
}
void MesgBroadcaster::AddListener(ZonesTargetMesgListener& zonesTargetMesgListener)
{
   zonesTargetMesgListeners.push_back(&zonesTargetMesgListener);
}
void MesgBroadcaster::AddListener(SportMesgListener& sportMesgListener)
{
   sportMesgListeners.push_back(&sportMesgListener);
}
void MesgBroadcaster::AddListener(HrZoneMesgListener& hrZoneMesgListener)
{
   hrZoneMesgListeners.push_back(&hrZoneMesgListener);
}
void MesgBroadcaster::AddListener(PowerZoneMesgListener& powerZoneMesgListener)
{
   powerZoneMesgListeners.push_back(&powerZoneMesgListener);
}
void MesgBroadcaster::AddListener(MetZoneMesgListener& metZoneMesgListener)
{
   metZoneMesgListeners.push_back(&metZoneMesgListener);
}
void MesgBroadcaster::AddListener(GoalMesgListener& goalMesgListener)
{
   goalMesgListeners.push_back(&goalMesgListener);
}
void MesgBroadcaster::AddListener(ActivityMesgListener& activityMesgListener)
{
   activityMesgListeners.push_back(&activityMesgListener);
}
void MesgBroadcaster::AddListener(SessionMesgListener& sessionMesgListener)
{
   sessionMesgListeners.push_back(&sessionMesgListener);
}
void MesgBroadcaster::AddListener(LapMesgListener& lapMesgListener)
{
   lapMesgListeners.push_back(&lapMesgListener);
}
void MesgBroadcaster::AddListener(RecordMesgListener& recordMesgListener)
{
   recordMesgListeners.push_back(&recordMesgListener);
}
void MesgBroadcaster::AddListener(EventMesgListener& eventMesgListener)
{
   eventMesgListeners.push_back(&eventMesgListener);
}
void MesgBroadcaster::AddListener(DeviceInfoMesgListener& deviceInfoMesgListener)
{
   deviceInfoMesgListeners.push_back(&deviceInfoMesgListener);
}
void MesgBroadcaster::AddListener(HrvMesgListener& hrvMesgListener)
{
   hrvMesgListeners.push_back(&hrvMesgListener);
}
void MesgBroadcaster::AddListener(CourseMesgListener& courseMesgListener)
{
   courseMesgListeners.push_back(&courseMesgListener);
}
void MesgBroadcaster::AddListener(CoursePointMesgListener& coursePointMesgListener)
{
   coursePointMesgListeners.push_back(&coursePointMesgListener);
}
void MesgBroadcaster::AddListener(WorkoutMesgListener& workoutMesgListener)
{
   workoutMesgListeners.push_back(&workoutMesgListener);
}
void MesgBroadcaster::AddListener(WorkoutStepMesgListener& workoutStepMesgListener)
{
   workoutStepMesgListeners.push_back(&workoutStepMesgListener);
}
void MesgBroadcaster::AddListener(TotalsMesgListener& totalsMesgListener)
{
   totalsMesgListeners.push_back(&totalsMesgListener);
}
void MesgBroadcaster::AddListener(WeightScaleMesgListener& weightScaleMesgListener)
{
   weightScaleMesgListeners.push_back(&weightScaleMesgListener);
}
void MesgBroadcaster::AddListener(BloodPressureMesgListener& bloodPressureMesgListener)
{
   bloodPressureMesgListeners.push_back(&bloodPressureMesgListener);
}

void MesgBroadcaster::OnMesg(Mesg& mesg)
{
   for (int i=0; i < (int)mesgListeners.size(); i++)
      mesgListeners[i]->OnMesg(mesg);

   switch (mesg.GetNum())
   {
      case FIT_MESG_NUM_FILE_ID:
      {
         FileIdMesg fileIdMesg(mesg);
         for (int i=0; i < (int)fileIdMesgListeners.size(); i++)
            fileIdMesgListeners[i]->OnMesg(fileIdMesg);
         break;
      }
      case FIT_MESG_NUM_FILE_CREATOR:
      {
         FileCreatorMesg fileCreatorMesg(mesg);
         for (int i=0; i < (int)fileCreatorMesgListeners.size(); i++)
            fileCreatorMesgListeners[i]->OnMesg(fileCreatorMesg);
         break;
      }
      case FIT_MESG_NUM_PAD:
      {
         PadMesg padMesg(mesg);
         for (int i=0; i < (int)padMesgListeners.size(); i++)
            padMesgListeners[i]->OnMesg(padMesg);
         break;
      }
      case FIT_MESG_NUM_SOFTWARE:
      {
         SoftwareMesg softwareMesg(mesg);
         for (int i=0; i < (int)softwareMesgListeners.size(); i++)
            softwareMesgListeners[i]->OnMesg(softwareMesg);
         break;
      }
      case FIT_MESG_NUM_CAPABILITIES:
      {
         CapabilitiesMesg capabilitiesMesg(mesg);
         for (int i=0; i < (int)capabilitiesMesgListeners.size(); i++)
            capabilitiesMesgListeners[i]->OnMesg(capabilitiesMesg);
         break;
      }
      case FIT_MESG_NUM_FILE_CAPABILITIES:
      {
         FileCapabilitiesMesg fileCapabilitiesMesg(mesg);
         for (int i=0; i < (int)fileCapabilitiesMesgListeners.size(); i++)
            fileCapabilitiesMesgListeners[i]->OnMesg(fileCapabilitiesMesg);
         break;
      }
      case FIT_MESG_NUM_MESG_CAPABILITIES:
      {
         MesgCapabilitiesMesg mesgCapabilitiesMesg(mesg);
         for (int i=0; i < (int)mesgCapabilitiesMesgListeners.size(); i++)
            mesgCapabilitiesMesgListeners[i]->OnMesg(mesgCapabilitiesMesg);
         break;
      }
      case FIT_MESG_NUM_FIELD_CAPABILITIES:
      {
         FieldCapabilitiesMesg fieldCapabilitiesMesg(mesg);
         for (int i=0; i < (int)fieldCapabilitiesMesgListeners.size(); i++)
            fieldCapabilitiesMesgListeners[i]->OnMesg(fieldCapabilitiesMesg);
         break;
      }
      case FIT_MESG_NUM_DEVICE_SETTINGS:
      {
         DeviceSettingsMesg deviceSettingsMesg(mesg);
         for (int i=0; i < (int)deviceSettingsMesgListeners.size(); i++)
            deviceSettingsMesgListeners[i]->OnMesg(deviceSettingsMesg);
         break;
      }
      case FIT_MESG_NUM_USER_PROFILE:
      {
         UserProfileMesg userProfileMesg(mesg);
         for (int i=0; i < (int)userProfileMesgListeners.size(); i++)
            userProfileMesgListeners[i]->OnMesg(userProfileMesg);
         break;
      }
      case FIT_MESG_NUM_HRM_PROFILE:
      {
         HrmProfileMesg hrmProfileMesg(mesg);
         for (int i=0; i < (int)hrmProfileMesgListeners.size(); i++)
            hrmProfileMesgListeners[i]->OnMesg(hrmProfileMesg);
         break;
      }
      case FIT_MESG_NUM_SDM_PROFILE:
      {
         SdmProfileMesg sdmProfileMesg(mesg);
         for (int i=0; i < (int)sdmProfileMesgListeners.size(); i++)
            sdmProfileMesgListeners[i]->OnMesg(sdmProfileMesg);
         break;
      }
      case FIT_MESG_NUM_BIKE_PROFILE:
      {
         BikeProfileMesg bikeProfileMesg(mesg);
         for (int i=0; i < (int)bikeProfileMesgListeners.size(); i++)
            bikeProfileMesgListeners[i]->OnMesg(bikeProfileMesg);
         break;
      }
      case FIT_MESG_NUM_ZONES_TARGET:
      {
         ZonesTargetMesg zonesTargetMesg(mesg);
         for (int i=0; i < (int)zonesTargetMesgListeners.size(); i++)
            zonesTargetMesgListeners[i]->OnMesg(zonesTargetMesg);
         break;
      }
      case FIT_MESG_NUM_SPORT:
      {
         SportMesg sportMesg(mesg);
         for (int i=0; i < (int)sportMesgListeners.size(); i++)
            sportMesgListeners[i]->OnMesg(sportMesg);
         break;
      }
      case FIT_MESG_NUM_HR_ZONE:
      {
         HrZoneMesg hrZoneMesg(mesg);
         for (int i=0; i < (int)hrZoneMesgListeners.size(); i++)
            hrZoneMesgListeners[i]->OnMesg(hrZoneMesg);
         break;
      }
      case FIT_MESG_NUM_POWER_ZONE:
      {
         PowerZoneMesg powerZoneMesg(mesg);
         for (int i=0; i < (int)powerZoneMesgListeners.size(); i++)
            powerZoneMesgListeners[i]->OnMesg(powerZoneMesg);
         break;
      }
      case FIT_MESG_NUM_MET_ZONE:
      {
         MetZoneMesg metZoneMesg(mesg);
         for (int i=0; i < (int)metZoneMesgListeners.size(); i++)
            metZoneMesgListeners[i]->OnMesg(metZoneMesg);
         break;
      }
      case FIT_MESG_NUM_GOAL:
      {
         GoalMesg goalMesg(mesg);
         for (int i=0; i < (int)goalMesgListeners.size(); i++)
            goalMesgListeners[i]->OnMesg(goalMesg);
         break;
      }
      case FIT_MESG_NUM_ACTIVITY:
      {
         ActivityMesg activityMesg(mesg);
         for (int i=0; i < (int)activityMesgListeners.size(); i++)
            activityMesgListeners[i]->OnMesg(activityMesg);
         mesgWithEventBroadcaster.OnMesg(activityMesg);
         break;
      }
      case FIT_MESG_NUM_SESSION:
      {
         SessionMesg sessionMesg(mesg);
         for (int i=0; i < (int)sessionMesgListeners.size(); i++)
            sessionMesgListeners[i]->OnMesg(sessionMesg);
         mesgWithEventBroadcaster.OnMesg(sessionMesg);
         break;
      }
      case FIT_MESG_NUM_LAP:
      {
         LapMesg lapMesg(mesg);
         for (int i=0; i < (int)lapMesgListeners.size(); i++)
            lapMesgListeners[i]->OnMesg(lapMesg);
         mesgWithEventBroadcaster.OnMesg(lapMesg);
         break;
      }
      case FIT_MESG_NUM_RECORD:
      {
         RecordMesg recordMesg(mesg);
         for (int i=0; i < (int)recordMesgListeners.size(); i++)
            recordMesgListeners[i]->OnMesg(recordMesg);
         bufferedRecordMesgBroadcaster.OnMesg(recordMesg);
         break;
      }
      case FIT_MESG_NUM_EVENT:
      {
         EventMesg eventMesg(mesg);
         for (int i=0; i < (int)eventMesgListeners.size(); i++)
            eventMesgListeners[i]->OnMesg(eventMesg);
         mesgWithEventBroadcaster.OnMesg(eventMesg);
         break;
      }
      case FIT_MESG_NUM_DEVICE_INFO:
      {
         DeviceInfoMesg deviceInfoMesg(mesg);
         for (int i=0; i < (int)deviceInfoMesgListeners.size(); i++)
            deviceInfoMesgListeners[i]->OnMesg(deviceInfoMesg);
         break;
      }
      case FIT_MESG_NUM_HRV:
      {
         HrvMesg hrvMesg(mesg);
         for (int i=0; i < (int)hrvMesgListeners.size(); i++)
            hrvMesgListeners[i]->OnMesg(hrvMesg);
         break;
      }
      case FIT_MESG_NUM_COURSE:
      {
         CourseMesg courseMesg(mesg);
         for (int i=0; i < (int)courseMesgListeners.size(); i++)
            courseMesgListeners[i]->OnMesg(courseMesg);
         break;
      }
      case FIT_MESG_NUM_COURSE_POINT:
      {
         CoursePointMesg coursePointMesg(mesg);
         for (int i=0; i < (int)coursePointMesgListeners.size(); i++)
            coursePointMesgListeners[i]->OnMesg(coursePointMesg);
         break;
      }
      case FIT_MESG_NUM_WORKOUT:
      {
         WorkoutMesg workoutMesg(mesg);
         for (int i=0; i < (int)workoutMesgListeners.size(); i++)
            workoutMesgListeners[i]->OnMesg(workoutMesg);
         break;
      }
      case FIT_MESG_NUM_WORKOUT_STEP:
      {
         WorkoutStepMesg workoutStepMesg(mesg);
         for (int i=0; i < (int)workoutStepMesgListeners.size(); i++)
            workoutStepMesgListeners[i]->OnMesg(workoutStepMesg);
         break;
      }
      case FIT_MESG_NUM_TOTALS:
      {
         TotalsMesg totalsMesg(mesg);
         for (int i=0; i < (int)totalsMesgListeners.size(); i++)
            totalsMesgListeners[i]->OnMesg(totalsMesg);
         break;
      }
      case FIT_MESG_NUM_WEIGHT_SCALE:
      {
         WeightScaleMesg weightScaleMesg(mesg);
         for (int i=0; i < (int)weightScaleMesgListeners.size(); i++)
            weightScaleMesgListeners[i]->OnMesg(weightScaleMesg);
         break;
      }
      case FIT_MESG_NUM_BLOOD_PRESSURE:
      {
         BloodPressureMesg bloodPressureMesg(mesg);
         for (int i=0; i < (int)bloodPressureMesgListeners.size(); i++)
            bloodPressureMesgListeners[i]->OnMesg(bloodPressureMesg);
         break;
      }

      default:
         break;
   }
}

void MesgBroadcaster::OnMesgDefinition(MesgDefinition& mesgDef)
{
   for (int i=0; i < (int)mesgDefinitionListeners.size(); i++)
      mesgDefinitionListeners[i]->OnMesgDefinition(mesgDef);
}

} // namespace fit

